/**
 * Created by Administrator on 2017/3/30.
 */
/**
 * Created by win7 on 2017/3/14.
 */
import React from "react";
import "./css/OrderTree.css";
import {hashHistory} from "react-router";
/*信息列表*/


export default class OrderDetail extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            orders: [],
            total: 0,
            type: 0
        }

        this.type = {
            1: "成衣订单",
            2: "辅料订单",
            3: "布料订单",
            4: "印染订单",
            5: "纱线订单",
        }
    }

    searchTree(oid) {
        hashHistory.push("/orderTree");
    }

    componentWillMount() {
        this.state = {
            type: 0
        }
        this.addItem();
    }

    addItem() {
        let orders = this.props.orders;
        let type = this.props.type || 0;
        let neworders = [];
        for (let i = 0; i < orders.length; i++) {
            if (type == 0) {
                neworders = orders;
            } else if (type == 1) {
                if (orders[i].orderType == 1 || orders[i].orderType == 3) {
                    neworders.push(orders[i])
                }
            } else if (type == 3) {
                if (orders[i].orderType == 3) {
                    neworders.push(orders[i])
                }
            } else if (type == 2) {
                if (orders[i].orderType == 2) {
                    neworders.push(orders[i])
                }
            }


        }
        return neworders.map((context, index) => {
            let state = this.type[context.orderType];
            return (
                <div key={index} className="orderManage">
                    <div className="orderManage_1">
                        <div className="orderManage_orderGoodsNum_account">
                            <div className="orderManage_oid">订单：{context.oid}</div>
                            <div className="orderManage_partAName">供应商：{context.partAName}</div>
                            <div className="orderManage_orderType">订单类型：{state}</div>

                            <div className="orderManage_orderGoodsNum">商品数量：{context.orderGoodsNum}</div>

                        </div>
                        <div className="orderManage_account_dd">
                            <p className="orderManage_account">{context.account / 100}</p>
                            <p className="orderManage_account_d">订单金额</p>


                        </div>
                        <div className="orderManage_account_detail"><p className="orderManage_account_detail_d">详情</p></div>
                    </div>

                </div>
            )
        })
    }

    onSure(size, num) {
        this.props.requestdata(size, num)
    }


    render() {
        return (
            <div className="order_lists clear">
                <ul style={{clear: "both"}}>
                    {
                        this.addItem()
                    }
                </ul>
            </div>
        )
    }
}